﻿using Microsoft.EntityFrameworkCore;
using Resume.Model;

namespace Resume.ModelMigration;

public class XLZFContext: DbContext
{
    /// <summary>
    /// 上下文
    /// </summary>
    public XLZFContext()
    {
        //同时为了除此应用的时候代码能够自动创建数据库可以在EFLearnDbContext里添加，程序运行时保证数据库创建。
        Database.EnsureCreated();
    }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseMySql("server=120.48.37.178;user id=root;password=Aa111111;database=ResumeManage", ServerVersion.Parse("5.6.50-mysql"));
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<FieldClassDict>().Property(x => x.Id).ValueGeneratedOnAdd();//设置Id自增

        modelBuilder.Entity<FieldSettingDict>().Property(x => x.Id).ValueGeneratedOnAdd();//设置Id自增

        modelBuilder.Entity<UsersDict>().Property(x => x.Id).ValueGeneratedOnAdd();//设置Id自增
    }

    public DbSet<FieldClassDict> FieldClassDict { get; set; }
    public DbSet<FieldSettingDict> FieldSettingDict { get; set; }
    public DbSet<UsersDict> UsersDict { get; set; }
}